Skip to content

Conversation

@RobertoRoos
Copy link
Contributor

I added __enter__ and __exit__ methods to enable context manager support. This makes uses of a device more pythonic.

I also renamed device to Device, since it's a class. I added an alias with a warning for device, so existing code would keep running.

Having said this out loud, the class renaming should have been a separate PR. Let me know and I'll split it again.

@RobertoRoos
Copy link
Contributor Author

Usage is now:

h = hid.Device()
with h.open(...):
    # pass

I would prefer:

with hid.open(...) as h:
    # pass

Much like opening a file.
Something like this could be more easily implemented with #109 .

@prusnak
Copy link
Member

prusnak commented Feb 11, 2021

Can you please add backwards compatibility for the rename, so also the old device would still work the same way? Maybe just device = Device would suffice.

@RobertoRoos
Copy link
Contributor Author

@prusnak I've added exactly that.
device extends Device with a warning in the constructor.

Copy link
Contributor

@jonasmalacofilho jonasmalacofilho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I'm sorry for the unsolicited review, but as the maintainer of project that depends on cython-hidapi, I reviewed this and also tested it for backwards compatibility.

I left a few comments, please take a look at them when possible.

@RobertoRoos
Copy link
Contributor Author

Reverted all (potentially) breaking changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants